//
//  YiDaTabBarController.swift
//  YiDa
//
//  Created by zhoufei on 16/6/26.
//  Copyright © 2016年 ZhouFei. All rights reserved.
//

import UIKit

class YiDaTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        YiDaLocationManager.main
        // Do any additional setup after loading the view.
        
        let timer:NSTimer = NSTimer.scheduledTimerWithTimeInterval(3.0, target: self, selector: #selector(YiDaTabBarController.timer), userInfo: nil, repeats: true)
        timer.fire()
    }
    
    func timer(){
        if YiDaUser.main.isLogin(){
            let param:Dictionary<String,AnyObject> = ["userId":NSNumber(int: YiDaUser.main.userId!),"lng":YiDaLocation.main.lng,"lat":YiDaLocation.main.lat,"address":YiDaLocation.main.address]
            YiDaNet.main.request(UPDATE_LOCATION, param: param, completionHandler: { (inner) in
                do{
                    try inner()
                }catch let error{
                    print(error)
                }
            })
            
        }
        print(YiDaLocation.main.address)
    }
    
    override func viewDidAppear(animated: Bool) {
        if !YiDaUser.main.isLogin(){
            let login:YiDaLoginViewController = self.storyboard!.instantiateViewControllerWithIdentifier("login") as! YiDaLoginViewController
            login.loginSuccess = {() in
                self.view.makeToast("登陆成功")
            }
            self.presentViewController(login, animated: true, completion: nil)
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
